<template>
  <div class="dialog4">
    <el-dialog
        :title="dialog4.title"
        :visible.sync="dialog4.show"
        :close-on-click-modal='false'
        :close-on-press-escape='false'
        :modal-append-to-body="false"
        :before-close='closeDialog'
        width="30%">
      <div class="form">
        <el-form ref="form" :model="formData" label-width="120px" style="margin:10px;width:auto;">
          <el-form-item label="地址：" prop="address">
            <span>{{ formData.address }}</span>
          </el-form-item>
          <el-form-item label="价格：" prop="price">
            <span>{{ formData.price }}</span>
          </el-form-item>
          <el-form-item label="详情：" prop="detail">
            <span>{{ formData.detail }}</span>
          </el-form-item>
          <el-form-item class="text_right">
            <el-button @click="dialog4.show = false">取消</el-button>
            <el-button type="primary" @click='onSubmit("form")'>申请</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import houseApi from '../api/house.js'
import {getUser} from '../utils/auth'

export default {
  name: 'useredit-dialog',
  props: {
    dialog4: Object,
    formData: Object
  },
  data() {
    return {
      index: '',
    }
  },
  computed: {
    user() {
      return getUser();
    }
  },
  methods: {
    closeDialog(done) {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields();
      }
      done();
    },
    onSubmit(form) {
      this.$confirm('您确定要申请入住吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$refs[form].validate(valid => {
          if (valid) {

            let pojo

            if (isNaN(this.formData.userlist_Name)) {
              if (this.formData.userlist_Name == "无") {
                pojo = {
                  houseId: this.formData.id,
                  address: this.formData.address,
                  price: this.formData.price,
                  status: "申请中",
                  detail: this.formData.detail,
                  userlist_Id: this.user.id,
                  userlist_Name: this.user.name
                };
              }
            }
            houseApi.updateHouse(pojo).then(res => {
              //修改成功之后的处理
              if (res.data.flag) {
                this.$message({
                  message: "申请成功",
                  type: "success"
                });
                this.dialog4.show = false;
                this.$emit('update');
              } else {
                this.$message({
                  message: "申请失败",
                  type: "warning"
                });

              }

            });
          }
        });
      })
    }
  }
};
</script>

